<?php

	include_once("./db.php"); 
	
	$userId = $_SESSION["user"]["Id"];

	$res = db_select("SELECT 
		e.Id, 
		e.Name 
		FROM
			Element e,
			TagElement te,
			TagUser tu
		WHERE
			e.Id = te.ElementId  AND
			te.TagId = tu.TagId AND
			tu.UserId = $userId AND
			(Starter
			OR EXISTS (SELECT 1 FROM UserElement ue WHERE ue.UserId = $userId AND ue.ElementId = e.Id))");

	while($item = mysql_fetch_array($res, MYSQL_ASSOC))
		$ret["Elements"][] = $item;
	
	echo json_result_encode($ret);

?>